﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "EnumAndStruct/GrowthEnumAndStruct.h"
#include "Trigger.generated.h"

class USphereComponent;
class UBoxComponent;
class UPrimitiveComponent;


/**
 *  触发相关
 */

UCLASS()
class GROWTHDEPENDENT_API ATrigger : public AActor
{
	GENERATED_BODY()

public:
	ATrigger();

protected:
	virtual void BeginPlay() override;

	virtual void OnConstruction(const FTransform& Transform) override;

	// 触发类初始化
	void TriggerInit();

	// 触发后的状态
	UPROPERTY(EditAnywhere, Category="默认")
	ETriggeredState TriggeredState = ETriggeredState::ETS_Germinate;

	// 碰撞类型
	UPROPERTY(EditAnywhere, DisplayName="碰撞类型", Category="默认")
	EPlantCollision PlantCollision = EPlantCollision::EPC_Box;

	UPROPERTY(VisibleDefaultsOnly, Category="组件")
	TObjectPtr<UBoxComponent> Box;

	// 盒默认大小
	UPROPERTY(EditAnywhere, meta=(EditCondition = "PlantCollision == EPlantCollision::EPC_Box", EditConditionHides), Category="默认")
	FVector BoxSize = FVector(32.f, 32.f, 32.f);

	UPROPERTY(VisibleDefaultsOnly, Category="组件")
	TObjectPtr<USphereComponent> Sphere;

	// 球形碰撞体默认大小
	UPROPERTY(EditAnywhere, meta=(EditCondition = "PlantCollision == EPlantCollision::EPC_Sphere", EditConditionHides), Category="默认")
	float SphereSize = 50.f;

	/**
	 * @brief 碰撞绑定
	 * @param PrimitiveComponent 组件
	 */
	void OverlapBind(const TObjectPtr<UPrimitiveComponent> PrimitiveComponent);

	// 重叠碰撞
	UFUNCTION()
	void OverlapCollision(
		UPrimitiveComponent* OverlappedComp,
		AActor* OtherActor,
		UPrimitiveComponent* OtherComp,
		int32 OtherBodyIndex,
		bool bFromSweep,
		const FHitResult& SweepResult);

public:
};
